package com.qc.controller;

import com.qc.dto.Result;
import com.qc.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static org.python.modules.math.e;

@RestController
@RequestMapping("room")
@CrossOrigin
public class RoomController {

    @Autowired
    private IRoomService roomService;

    /** 创建房间 */
    @PostMapping("create")
    public Result<String> createRoom(@RequestBody Map<String, Object> request) {
        String roomId = roomService.createRoom(request);
        return Result.successResult(roomId);
    }

    /** 加入房间 */
    @PostMapping("join")
    public Result<String> joinRoom(@RequestBody Map<String, Object> request) {
        String roomId = (String) request.get("roomId");
        String userId = (String) request.get("userId");
        boolean success = roomService.joinRoom(roomId, userId);
        if (success) {
            return Result.successResult("加入房间成功");
        } else {
            return Result.error("500", "服务异常");
        }
    }

    // 后续可添加视频通话和屏幕共享的相关接口
}